package com.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.entity.SysBusinessInfo;
import com.project.entity.SysStore;
import com.project.entity.SysUser;
import com.project.mapper.SysStoreMapper;
import com.project.mapper.SysUserMapper;
import com.project.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 * @Author(作者) 王崇人
 * @Description(接口的描述): 商铺用户业务层接口实现类
 *：@version（开发的版本）：1.0
 * @Date(创建时间)：2021-10-08
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Autowired
    private SysStoreMapper sysStoreMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public void addStore(SysUser sysUser, SysBusinessInfo sysBusinessInfo) {
        sysUserMapper.addStore(sysUser, sysBusinessInfo);
    }

    @Override
    public SysUser findById(Integer userId) {
        return sysUserMapper.findById(userId);
    }

    @Override
    public List<SysStore> showStore(Integer userId) {
        if (this.findById(userId) != null) {
            return sysStoreMapper.findUserIdByStore(userId);
        }
        return null;
    }

    @Override
    public void add(String sName, String sDoorimage, String storeCode, int userId, String pName, String pNum) {
        SysStore sysStore = new SysStore();
        sysStore.setSName(sName);
        sysStore.setSDoorimage(sDoorimage);
        sysStore.setStoreCode(storeCode);
        sysStore.getUser().setUserId(userId);
        sysUserMapper.add(sysStore, userId);
        sysUserMapper.addPrincipal(pName, pNum, sysStore.getPkStoreid());
    }
}
